package com.epam.kulibaba.helpers.testSupport;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.openqa.selenium.WebDriver;
import org.testng.Assert;
import org.testng.Reporter;

import com.epam.kulibaba.components.PanelCriterias.PanelCornerCriterias;
import com.epam.kulibaba.components.catalog.ProductsCatalog;
import com.epam.kulibaba.components.catalog.navigator.CatalogNavigatorPager;
import com.epam.kulibaba.helpers.Class.Catalog;
import com.epam.kulibaba.helpers.Class.Product;

public class PanelCriteriasHelper {	

	public static List<String> getProducersAllProductsList(Catalog catalog) {
		Reporter.log("Get all product's producers from products catalog");
		List<Product> myProducts = new ArrayList<Product>(catalog.globals);
		List<String> nameProducers = new ArrayList<String>();
		for (Product item : myProducts) {
			String name = item.getName().toLowerCase();
			nameProducers.add(name.substring(0, name.indexOf(" ")));
		} // System.out.println(nameProducers);
		return nameProducers;
	}

	public static void checkProducersFilterTest(HashSet<String> setProducers,
			List<String> nameProducers) {
		Reporter.log("Check the presence of all producers of product in category");
		Assert.assertEquals(setProducers.containsAll(nameProducers), true);
	}	

	public static void chekPresentsFunctionInProducts(PanelCornerCriterias panelCornerCriterias,String functionName, WebDriver driver, CatalogNavigatorPager catalogPager,
			CatalogNavigatorPager linkForward, ProductsCatalog productsCatalog ){
		Reporter.log("Check availability of function in products");	
		PanelCornerCriterias.setFunctionFilter(panelCornerCriterias, functionName);		
		List<String> shortDescription = ProductsCatalog.getAllProductsListShortDescription(driver,
				catalogPager, linkForward, productsCatalog);
		for (String desc : shortDescription) {
			Assert.assertEquals(desc.contains(functionName.toLowerCase()), true);
		}
	}
}
